package main

import "fmt"

// 	"rsc.io/quote"

func mainFunc() {
	res := getSum(1, 2)
	fmt.Println(res)
	sum, diff := getRes(1, 2)
	fmt.Printf("sum is %v, diff is %v", sum, diff)
	fmt.Println("")
	fmt.Printf("getRes is %v, type is %T", getRes2, getRes2)
	fmt.Println("")
	//我们也可以以声明变量的形式声明函数
	var getRes3 = func(n1, n2 int) (sum, difference int) {
		sum = n1 + n2
		difference = n1 - n2
		return
	}
	a, b := getRes3(1, 2)
	fmt.Println(a, b)
	//立即调用的匿名函数
	a1, b1 := func(n1, n2 int) (sum, difference int) {
		sum = n1 + n2
		difference = n1 - n2
		return
	}(1, 2)
	fmt.Println(a1, b1)

}

func getSum(n1 int, n2 int) int {
	sum := n1 + n2
	return sum
}
func getRes(n1 int, n2 int) (int, int) {
	sum := n1 + n2
	difference := n1 - n2
	return sum, difference
}

/**

函数不是变量，但他也存在与内存中，存在内存地址

函数名的本质就是一个指向其函数内存地址的指针常量
*/
func getRes2(n1, n2 int) (sum, difference int) {
	sum = n1 + n2
	difference = n1 - n2
	return
}
